package de.wittekind.bundesjugendspiele.client.management.model;
import java.io.IOException;
import java.io.Serializable;
import java.rmi.server.UnicastRemoteObject;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Iterator;

import de.wittekind.bundesjugendspiele.server.interfaces.Discipline;
import de.wittekind.bundesjugendspiele.server.interfaces.Riege;
import de.wittekind.bundesjugendspiele.server.interfaces.RiegenLoader;
import de.wittekind.bundesjugendspiele.server.interfaces.Schueler;
import de.wittekind.bundesjugendspiele.server.interfaces.Schueler.Gender;
import de.wittekind.bundesjugendspiele.server.interfaces.Try;
import de.wittekind.bundesjugendspiele.server.interfaces.Unit;


public class LocalSchueler extends UnicastRemoteObject implements Schueler, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8714515479107637597L;
	
	RiegenLoader r;
	String firstname, lastname;
	Gender gender;
	GregorianCalendar bday;
	static HashMap<Riege, Integer> flags;
	int SCHUELER_MAX;
	private String form;
	Discipline [] discs;
	
	public LocalSchueler(RiegenLoader r, String firstname, String lastname, Gender gender,
			GregorianCalendar bday, String form, Discipline[] discs) throws IOException {
			this.r = r;
			this.firstname = firstname;
			this.lastname = lastname;
			this.bday = bday;
			this.gender = gender;
			this.discs = discs;
	}

	@Override
	public int getID() throws IOException {
		return -1;
	}

	@Override
	public String getLastName() throws IOException {
		// TODO Auto-generated method stub
		return lastname;
	}

	@Override
	public String getFirstName() throws IOException {
		// TODO Auto-generated method stub
		return firstname;
	}

	@Override
	public GregorianCalendar getBirthday() throws IOException {
		// TODO Auto-generated method stub
		return bday;
	}

	@Override
	public int getPoints() throws IOException {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	@Deprecated
	public int getTry() throws IOException {
		// TODO Auto-generated method stub
		return 0;
	}

	private static class LocalTry extends UnicastRemoteObject implements Try {

		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;
		Unit u;
		Discipline d;
		
		static public Try[] LocalTriesForDisciplines (Discipline[] discs) throws IOException {
			Try [] tries = new Try[8];
			int i = 0;
			int t = 0;
			while (t <= 3) {
				switch (discs[t]) {
				case AUSDAUER:
				case AUSDAUER1000:
				case AUSDAUER2000:
				case AUSDAUER3000:
				case AUSDAUER800:
					tries[i]= new LocalTry(Unit.s, discs[t]);
					i++;
					t++;
					break;
				case SPRUNG:
				case HOCHSPRUNG:
				case WEITSPRUNG:
					tries[i]     = new LocalTry(Unit.m, discs[t]);
					tries[i + 1] = new LocalTry(Unit.s, discs[t]);
					tries[i + 2] = new LocalTry(Unit.s, discs[t]);
					i += 3;
					t++;
					break;
				case SPRINT:
				case SPRINT100:
				case SPRINT50:
				case SPRINT75:
					tries[i]= new LocalTry(Unit.s, discs[t]);
					i++;
					t++;
					break;
				case STOSS:;
				case STOSS3000:
				case STOSS4000:
				case STOSS5000:
				case STOSS6250:
				case WURF:
				case WURF200:
				case WURF80:
					tries[i]     = new LocalTry(Unit.m, discs[t]);
					tries[i + 1] = new LocalTry(Unit.s, discs[t]);
					tries[i + 2] = new LocalTry(Unit.s, discs[t]);
					i += 3;
					t++;
					break;
				default:
					break;
					
				}
			}
			return tries;
		}
		
		protected LocalTry ( Unit u,Discipline d ) throws IOException {
			this.u = u;
			this.d = d;
		}
		
		@Override
		public double getValue() throws IOException {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public Unit getUnit() throws IOException {
			// TODO Auto-generated method stub
			return u;
		}

		@Override
		public Discipline getDiscipline() throws IOException {
			// TODO Auto-generated method stub
			return d;
		}

		@Override
		public void setValue(double value) throws IOException {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void setUnit(Unit unit) throws IOException {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void setDiscipline(Discipline discipline) throws IOException {
			// TODO Auto-generated method stub
			
		}

		@Override
		public int getID() throws IOException {
			// TODO Auto-generated method stub
			return 0;
		}
		
	}
	
	@Override
	public Try[] getTries() throws IOException {
		Try [] t = null;
		try {
		t = LocalTry.LocalTriesForDisciplines(discs);
		} catch ( NullPointerException e ) {
			System.out.println(this);
			System.out.println(t);
		}
		
		return t;
	}

	@Override
	@Deprecated
	public int getCurrentDiscipline() throws IOException {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Gender getGender() throws IOException {
		// TODO Auto-generated method stub
		return gender;
	}

	@Override
	public String getForm() throws IOException {
		// TODO Auto-generated method stub
		return form;
	}

	@Override
	@Deprecated
	public void setTry(int nTry) throws IOException {
		// TODO Auto-generated method stub

	}

	@Override
	public void setTries(Try[] tries) throws IOException {
		// TODO Auto-generated method stub

	}
	
	@Override
	public Try createNewTry() throws IOException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setFirstName(String nFirstName) throws IOException {
		// TODO Auto-generated method stub

	}

	@Override
	public void setBirthday(GregorianCalendar nDate) throws IOException {
		// TODO Auto-generated method stub

	}

	@Override
	public void setGender(Gender nGender) throws IOException {
		// TODO Auto-generated method stub

	}

	@Override
	public void setForm(String nClass) throws IOException {
		// TODO Auto-generated method stub

	}

	@Override
	@Deprecated
	public void setDiscipline(int id, Discipline d) throws IOException {
		// TODO Auto-generated method stub

	}

	@Override
	public void setLastName(String string) throws IOException {
		// TODO Auto-generated method stub

	}

	@Override
	public String toString () {
		
		return firstname + " " + lastname + " || " + form + " || " + " || " + bday + " || ";
				
	}

	@Override
	public int getNote() throws IOException {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public boolean hasEhrenurkunde() throws IOException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean hasSiegerurkunde() throws IOException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void setActive(boolean b) throws IOException {
		// TODO Auto-generated method stub
		
	}
	
}
